package com.sun.hunk.hibernate.domain.impl;

import com.sun.hunk.hibernate.domain.CodeType;
import com.sun.hunk.hibernate.domain.GenericCode;
import com.sun.hunk.hibernate.domain.GenericCodeValue;
import java.util.Set;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 *
 * @author sunil
 */
@Entity
@Table(name = "generic_code")
public class GenericCodeImpl implements GenericCode {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Long id;
    @Column(name = "code")
    private String code;
    @Column(name = "description")
    private String description;    
    @JoinColumn(name = "code_type_id", referencedColumnName = "id")
    @ManyToOne(targetEntity=CodeTypeImpl.class)
    private CodeType codeType;    
    @OneToMany(mappedBy = "genericCode",targetEntity=GenericCodeValueImpl.class)
    private Set<GenericCodeValue> genericCodeValueSet;

    public GenericCodeImpl() {
    }

    public GenericCodeImpl(Long id) {
        this.id = id;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }
    
    public CodeType getCodeType() {
        return codeType;
    }

    public void setCodeType(CodeType codeType) {
        this.codeType = codeType;
    }

    public Set<GenericCodeValue> getGenericCodeValueSet() {
        return genericCodeValueSet;
    }

    public void setGenericCodeValueSet(Set<GenericCodeValue> genericCodeValueSet) {
        this.genericCodeValueSet = genericCodeValueSet;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof GenericCodeImpl)) {
            return false;
        }
        GenericCodeImpl other = (GenericCodeImpl) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.cong.logiware.hibernate.domain.GenericCode[id=" + id + "]";
    }

}
